package com.controller;

import com.model.MyUser;
import com.service.MyuserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("我的用户")
@RestController
@RequestMapping("/myuser")
public class MyuserController {

    @Autowired
    private MyuserService myuserService ;

    //用户添加方法的对外接口
    @RequestMapping(value = "/addUser" , method = RequestMethod.GET)
    public int addUser (MyUser myUser){
        System.out.println("进入用户添加方法") ;
        return myuserService.addMyUser(myUser);
     }

     //用户修改方法的对外接口
     @RequestMapping(value = "/updateMyuser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public int updateUser (MyUser myUser){
        System.out.println("进入用户修改方法，修改的主键为："+myUser.getUserid());
        return myuserService.updateMyUser(myUser);
    }

    //用户删除方法的对外接口
    @RequestMapping(value = "/deleteMyuser",method = RequestMethod.GET)
    public int deleteUser (int userid){
        System.out.println("进入用户删除方法，主键为："+userid);
        return myuserService.deleteMyUser(userid);
    }

    //用户查找方法的对外接口
    @RequestMapping(value = "/getUser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public MyUser getUser (int userid){
        System.out.println("进入根据主键id进行用户查找方法，主键为："+userid);
        return myuserService.getUser(userid);
    }

    //查询全部用户信息方法的对外接口
    @CrossOrigin //解决跨域问题
    @RequestMapping(value = "/getAll",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyUser> getAll(@RequestBody MyUser myUser){
        System.out.println("进入查询用户全部信息方法");
        //System.out.println(myUser.getUsername()+"======"+myUser.getPwd());
        return myuserService.getAllMyUsers(myUser);
    }


}
